<template>
	<view class="content">
		<view class="top_tip">
			<text>1.打开支付宝搜索收款人微信进行转账</text>
			<text>2.返回此页面上传转账凭证</text>
		</view>
		<view class="payinfo">
			<view class="payinfo_list">
				<view class="payinfo_fl">收款人姓名</view>
				<view class="payinfo_txt">{{payDatas.name}}</view>
			</view>
			<view class="payinfo_list">
				<view class="payinfo_fl">收款人支付宝</view>
				<view class="payinfo_txt">{{payDatas.account}}</view>
				<view class="copy">复制</view>
			</view>
			<view class="payinfo_list">
				<view class="payinfo_fl">支付宝二维码</view>
				<view class="payinfo_image" @click="goPreview(payDatas.code)">
					<image  :src="payDatas.code" mode="aspectFit"></image>
				</view>
			</view>
		</view>
		<view class="upload">
			<view class="payinfo_list">
				<view class="payinfo_fl">上传转账凭证</view>
				<view class="payinfo_image">
					<image  :src="confirmVoucher == '' ? dafultImage : confirmVoucher" mode="aspectFit" @click="upload(confirmVoucher)"></image>
					<image v-if="confirmVoucher != ''" class="closeImg" src="https://taobaoke-paimai.oss-cn-beijing.aliyuncs.com/close.png" mode="" @click="cancel"></image>
				</view>
			</view>
		</view>
		
		<view class="tip_txt" v-if="payDatas.name == ''">该卖家没有绑定支付宝收款，请选择其他支付方式</view>
		
		<view class="bottom" v-if="payDatas.name != ''">
			<view class="submit" @click="gopay">确认支付</view>
		</view>
	</view>
</template>

<script>
	import urlConfig from '@/common/api/config.js'
	export default {
		data() {
			return {
				type:'',
				id:'',
				confirmVoucher:'',
				payDatas:{},
				dafultImage:'https://taobaoke-paimai.oss-cn-beijing.aliyuncs.com/upload.png',
				buyId:''
			}
		},
		onLoad(options) {
			console.log(options)
			this.type = options.payType
			this.id = options.id;
			this.buyId = options.buyId
			this.getPayInfo()
			
		},
		methods: {
			getPayInfo: function () {
				this.api.getPayInfo({
					type:this.type,
					id:this.id
				}).then(res => {
					console.log(res)
					this.payDatas = res.data;
				})
			},
			// 删除上传凭证
			cancel: function () {
				this.confirmVoucher = "";
			},
			// 上传凭证
			upload: function (confirmVoucher) {
				let that = this;
				if (confirmVoucher == '') {
					uni.chooseImage({
					    count: 1, //默认9
					    sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					    sourceType: ['album'], //从相册选择
					    success: (chooseImageRes) => {
							const tempFilePaths = chooseImageRes.tempFilePaths;
							uni.uploadFile({
								url: urlConfig + 'uploadService', //接口地址
								filePath: tempFilePaths[0],
								name: 'file',
								success: (res) => {
									console.log(res); 
									var data = JSON.parse(res.data);
									console.log(data,"======")
									that.confirmVoucher = data.data.data
								}
							});
						}
					});	
					
				} else {
					this.tui.toast('凭证已经上传')
				}
			},
			// 确认支付
			gopay: function () {
				let that = this;
				if (that.confirmVoucher == '') {
					that.tui.toast('请上传支付凭证');
					return
				}
				this.api.uploadPayInfo({
					id:that.buyId,
					confirmVoucher:that.confirmVoucher,
					payType:that.type
				}).then(res => {
					console.log(res)
					that.tui.toast(res.data)
					setTimeout(function () {
						uni.$emit('goTake',{msg:'页面更新'});
						uni.$emit('update',{msg:'页面更新'});
						uni.$emit('SalesOrder',{msg:'页面更新'});
					},500)
					setTimeout(function () {
						uni.redirectTo({
							url: '../../../user/userPayBill/userPayBill?navType=1',
						});
					},1500)
				})
				
				
			},
			// 查看大图
			goPreview: function (urls) {
				let urlsList = urls.split(" ");
				console.log(urlsList[0])
				uni.previewImage({
					current: urlsList[0],
					// loop: true,
					urls: urlsList
				})
			}
		}
	}
</script>

<style lang="less">
	page {
		width: 100%;
		box-sizing: border-box;
		letter-spacing: 3rpx;
		background: #FFFFFF;
		font-family: PingFang SC;
		font-size: 32rpx;
		color: #333333;
	}
	.content {
		width: 100%;
		box-sizing: border-box;
	}
	.top_tip {
		width: 100%;
		box-sizing: border-box;
		background: #F5F5F5;
		padding: 34rpx 50rpx;
		font-size: 26rpx;
		color: #666666;
		line-height: 50rpx;
		display: flex;
		flex-flow: column;
	}
	.payinfo {
		width: 100%;
		box-sizing: border-box;
		padding: 30rpx 40rpx;
		border-bottom: 20rpx solid #F5F5F5;
		.payinfo_list {
			width: 100%;
			box-sizing: border-box;
			display: flex;
			justify-content: flex-start;
			align-items: center;
			font-size: 28rpx;
			color: #666666;
			padding: 20rpx 0;
			.payinfo_fl {
				width: 210rpx;
				box-sizing: border-box;
			}
			.payinfo_txt {
				font-size: 30rpx;
				color: #212121;
				line-height: 44rpx;
				font-weight: 500;
			}
			.copy {
				width: 74rpx;
				line-height: 34rpx;
				text-align: center;
				border: 1rpx solid #707070;
				font-size: 22rpx;
				color: #666666;
				margin-left: 50rpx;
				border-radius: 22rpx;
			}
			.payinfo_image {
				width: 140rpx;
				height: 191rpx;
				
				image {
					width: 100%;
					height: 100%;
				}
				
			}
			
		}
	}
	.upload {
		width: 100%;
		box-sizing: border-box;
		padding: 40rpx;
		.payinfo_list {
			width: 100%;
			box-sizing: border-box;
			display: flex;
			justify-content: flex-start;
			align-items: center;
			font-size: 28rpx;
			color: #666666;
			padding: 20rpx 0;
			.payinfo_fl {
				width: 210rpx;
				box-sizing: border-box;
			}
			.payinfo_image {
				width: 140rpx;
				height: 140rpx;
				position: relative;
				image {
					width: 100%;
					height: 100%;
				}
				.closeImg {
					width: 46rpx;
					height: 46rpx;
					position: absolute;
					top: -20rpx;
					right: -20rpx;
					z-index: 10;
				}
			}
			
		}
		
	}
	
	
	.bottom {
		width: 100%;
		box-sizing: border-box;
		background: #FFFFFF;
		padding: 30rpx 50rpx;
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 66;
		.submit {
			width: 100%;
			box-sizing: border-box;
			text-align: center;
			font-size: 30rpx;
			color: #FFFFFF;
			background: #E42221;
			border-radius: 8rpx;
			line-height: 94rpx;
		}
	}
	.tip_txt {
		width: 100%;
		box-sizing: border-box;
		font-size: 30rpx;
		text-align: center;
		color: #E42221;
		padding-top: 30rpx;
		
	}
	
	
	

</style>
